package com.berchen.算法.查找;

/**
 * 二分查找
 */
public class BinarySearch {
    public static void main(String[] args) {

        int arr[] ={1,5,6,9,10,43,54};
        int i = binarySearch(arr, 0, arr.length - 1, 1);
        System.out.println(i);

    }
    public static int binarySearch(int [] arr, int start ,int end ,int value ){

        if(start>end){
            return -1;
        }
        int mid =(start+end)/2;
        if(value<arr[mid]){
            return binarySearch(arr,start,mid-1,value);
        }
        else if(value>arr[mid]){
            return binarySearch(arr,mid+1,end,value);
        }
        else{
            return mid;
        }
    }

}
